<?php

declare (strict_types=1);

namespace App\Models\GameDB\Pet;

use Illuminate\Database\Eloquent\Model;

class PoolConfig extends Model
{
    protected $connection = 'mysql_game';
    protected $table = 'lottery_pet_pool_config';
    //protected $fillable = [];
    protected $guarded = [];

    //protected $casts = ['id' => 'int', 'user_id' => 'integer', 'amount' => 'integer', 'balance' => 'integer', 'created_at' => 'datetime', 'updated_at' => 'datetime'];

    public function one(array $filters, array $fields = ['*'])
    {
        if (!empty($fields)) {
            return $this->where($filters)->select($fields)->first();
        } else {
            return $this->where($filters)->first();
        }
    }

    public function info(){
        return $this->one(['id' => 1], ['notify_coin', 'broadcast_coin', 'top_gift_coin', 'novice_coin',
            'big_gift_coin', 'balance_coin', 'independent_switch', 'lucky_count', 'lucky_gift_template_id']);
    }

    public function balance_gift()
    {
        return $this->hasOne(\App\Models\MainDB\Gift::class, 'id', 'balance_gift_id');
    }

    public function mall_products()
    {
        return $this->hasOne(\App\Models\MainDB\MallProducts::class, 'id', 'balance_gift_id')->selectRaw('*,title as name');
    }
}
